package com.earthquake.monitor_system.controller;

import com.earthquake.monitor_system.excption.SystemException;
import com.earthquake.monitor_system.excption.businessSystemException;
import com.earthquake.monitor_system.utils.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@ControllerAdvice
public class projectExceptionHandler extends RuntimeException {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result doException(Exception ex){
        System.out.println(ex.getMessage());
        return Result.error("服务器内部异常!",null);
    }
    // 系统异常SystemException
    @ExceptionHandler(SystemException.class)
    @ResponseBody
    public Result doException(SystemException ex){
        System.out.println(ex.getMessage());
        return Result.error(ex.getCode(),ex.getMessage(),null);
    }
    // 业务异常
    @ExceptionHandler(businessSystemException.class)
    @ResponseBody
    public Result doException(businessSystemException ex){
        System.out.println(ex.getMessage());
        return Result.error(ex.getCode(),ex.getMessage(),null);
    }
}
